import { postForm, get, put } from '@/utils/request'

// 获取列表
export function getRoles() {
  return get('/auth/role/list')
}

export function add(optData) {
  return postForm('/auth/role', optData)
}

export function edit(optData) {
  optData['pkId'] = optData.id
  return put('/auth/role', optData)
}

export function del(ids) {
  return postForm('/auth/role/del/batch', { pkIds: JSON.stringify(ids) })
}

// 获取角色对应菜单列表
export function getRoleMenus(roleId) {
  return get('/auth/resource/menu/role/list', { roleId: roleId })
}

// 批量绑定权限
export function roleBindPms(roleId, resourceIds) {
  return postForm('/auth/role/resource/batch', { roleId: roleId, resourceIds: JSON.stringify(resourceIds) })
}

// 获取用户角色
export function getUserRoles(userId) {
  return get('/auth/role/user', { userId: userId })
}

// 批量用户绑定角色
export function userBindRoles(userId, roleIds) {
  return postForm('/auth/user/role/batch', { userId: userId, roleIds: JSON.stringify(roleIds) })
}
export default { add, edit, del, roleBindPms }
